package io.gitee.hejiang;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * SwaggerSqlBeanChecker bean
 * 
 * 启动阶段打印 bean 加载信息，用于调试
 */
@Component
public class SwaggerSqlBeanChecker
		implements BeanNameAware, BeanFactoryAware, ApplicationContextAware,
		InitializingBean, DisposableBean, BeanPostProcessor {
	private static final Logger logger = LoggerFactory
			.getLogger(SwaggerSqlBeanChecker.class);

	public SwaggerSqlBeanChecker() {
		logger.debug("bean 'BeanLifecyleWatcher' constructed");
	}

	@PostConstruct
	public void init() {
		logger.debug("bean 'BeanLifecyleWatcher' initialized");
	}

	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName)
			throws BeansException {
		return BeanPostProcessor.super.postProcessBeforeInitialization(bean,
				beanName);
	}

	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName)
			throws BeansException {
		logger.debug("bean '" + beanName + "' of class "
				+ bean.getClass().getCanonicalName() + " initialized");
		return BeanPostProcessor.super.postProcessAfterInitialization(bean,
				beanName);
	}

	@Override
	public void destroy() throws Exception {
		logger.debug("bean 'BeanLifecyleWatcher' destroyed");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		logger.debug("bean 'BeanLifecyleWatcher' afterPropertiesSet");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		logger.debug("bean 'BeanLifecyleWatcher' setApplicationContext");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		logger.debug("bean 'BeanLifecyleWatcher' setBeanFactory");
	}

	@Override
	public void setBeanName(String name) {
		logger.debug("bean 'BeanLifecyleWatcher' setBeanName");
	}
}
